const local = window.localStorage

const valToJsonstring = v => (typeof v === 'object' && v !== null ? JSON.stringify(v) : v)

/* 侧边栏状态 */
export const getSideBarState = () => local.getItem('sideBarState')
export const setSideBarState = v => local.setItem('sideBarState', valToJsonstring(v))

/* 用户信息 */
export const getUserInfo = () => local.getItem('ds_userInfo')
export const setUserInfo = v => local.setItem('ds_userInfo', valToJsonstring(v))

/* 对话按钮状态 */
export const getBtnStatus = () => {
  const s = local.getItem('ds_btnStatus')
  if (s && s !== 'null' && s.length > 0) return JSON.parse(s)
  else return null
}
export const setBtnStatus = v => local.setItem('ds_btnStatus', valToJsonstring(v))

/* 登录信息 */
export const getLoginInfo = () => {
  const s = local.getItem('ds_loginInfo')
  if (s && s !== 'null' && s.length > 0) return JSON.parse(s)
  else return null
}
export const setLoginInfo = v => local.setItem('ds_loginInfo', valToJsonstring(v))
export const clearLoginInfo = () => local.removeItem('ds_loginInfo')